﻿using MediatR;
using PLC.Domain.Models;
using PLC.Domain.Service.Service;

namespace PLC.Domain.Events.Handlers;

public class SaveProductionDataHandler:INotificationHandler<SaveProductionModel>
{
    private readonly ProductionDataService _productionDataService;

    public SaveProductionDataHandler(ProductionDataService productionDataService)
    {
        _productionDataService = productionDataService?? throw new ArgumentNullException(nameof(productionDataService));
    }
    /// <summary>
    /// 保存产品数据
    /// </summary>
    /// <param name="notification"></param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    public async Task Handle(SaveProductionModel notification, CancellationToken cancellationToken)
    {
        if (notification.ProductionDataList.Count==0)
        {
            return;
        }

        await _productionDataService.CreateAsync(notification.ProductionDataList);
    }
}